home *** CD-ROM | disk | FTP | other *** search
- Path: colossus.holonet.net!russell
- From: russell@news.mdli.com (Russell Blackadar)
- Newsgroups: comp.lang.c++
- Subject: Re: [Q]Assigning function pointer in C/C++.
- Date: 22 Jan 1996 19:22:29 GMT
- Organization: HoloNet National Internet Access System: 510-704-1058/modem
- Message-ID: <4e0o5l$fjc@colossus.holonet.net>
- References: <DL3JJu.5nB.0.queen@torfree.net> <4doc42$gsb@bmdhh222.bnr.ca> <ALUN.CHAMPION.96Jan19113523@g7240065.bridge.bst.bls.com> <4e09re$kit@populus.slu.se>
- NNTP-Posting-Host: jubal.mdli.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Thomas Johansson (Thomas.Johansson@stax.slu.se) wrote:
-
- : Is there any way that you can declare a variable to hold the resulting
- : pointer,
- : or must it be 'used' right away ?
-
- Yes, there's a way -- that's exactly what we're talking about here.
- You define a pointer, initialize it (perhaps at the same time, perhaps
- later), and then use it any time thereafter.
-
- : something like
-
- : typdef int (A::*p)(void) Fp; // Fp is a type...
-
- You made the mistake of putting two identifiers in your
- typedef; the name of the type above is the "p" even though
- it's in parentheses. The Fp is extra and causes an error.
- Correct:
- typedef int (A::*Fp)(void);
-
- BTW, you don't *have* to use a typedef.
-
- : Fp f = (a.*p); // the object a (of class A) has a member p
-
- Should be
- Fp f = &A::p; // where int p(void) is a member-function of A
-
- : int z = f();
-
- Should be
- int z = (a.*f)(); // note parens, .* has low precedence
-
- The operators .* and ->* are used to call the function, not to
- initialize the pointer.
-
- Earlier,
- Scott J. McCaughrin (sjmccaug@prairienet.org) wrote:
- : >bh332@freenet.toronto.on.ca (Karim Ladha) wrote:
- : >>
- : >>How is it possible to assign a declared variable in C++ a pointer to
- : >>some function member? If you know of a solution, post. Greatly appreciated.
- : >>
- [snip]
-
- : As usual, the C++ crowd has to bury us...
- : ... The author didn't ask about 'member' functions ...
-
- Ummm, in general I agree with your rant, but in this specific
- case the original author DID ask about member functions. You
- quoted it, in fact!
- --
- Russell Blackadar, russell@mdli.com
-